# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=lensfun
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.3.95
pkgrel=2
pkgdesc="Database of photographic lenses and a library that allows advanced access to the database (mingw-w64)"
arch=('any')
url="https://lensfun.github.io/"
license=("LGPL3")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-pkg-config"
             "${MINGW_PACKAGE_PREFIX}-python3"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-doxygen")
depends=("${MINGW_PACKAGE_PREFIX}-glib2"
         "${MINGW_PACKAGE_PREFIX}-libpng"
         "${MINGW_PACKAGE_PREFIX}-zlib")
options=('staticlibs' 'strip')
source=(${_realname}-${pkgver}.tar.gz::https://github.com/lensfun/lensfun/archive/v${pkgver}.tar.gz
        lensfun-update-data.patch
        cmake-mingw.patch
        lenstool.patch)
sha256sums=('82c29c833c1604c48ca3ab8a35e86b7189b8effac1b1476095c0529afb702808'
            '109c53303ad588d9e68796e9e0c3aeb0966632c8853e5c4edec321d2ce03ae45'
            '79bc7889f78afc29e3870897c8cfdd5e6439782e4d6a6dce68a5a42a32d35a03'
            '5ea8d41abba475f55a201a43b57a5b4053697c8e68a3c25f9b6f9d7952c63850')

prepare(){
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -p1 -i "${srcdir}/cmake-mingw.patch"
  patch -p1 -i "${srcdir}/lensfun-update-data.patch"
  patch -p1 -i "${srcdir}/lenstool.patch"
}

build() {
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir ${srcdir}/build-${MINGW_CHOST}
  cd ${srcdir}/build-${MINGW_CHOST}

  [[ $CARCH == x86_64 ]] && ENABLESSE2="-DBUILD_FOR_SSE2=ON"
  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=;-DSETUP_PY_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DSETUP_PY_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DBUILD_STATIC=OFF \
    -DBUILD_AUXFUN=ON \
    -DBUILD_LENSTOOL=ON \
    -DBUILD_TESTS=OFF \
    -DBUILD_FOR_SSE=ON \
    -DBUILD_DOC=OFF \
    $ENABLESSE2 \
    ../${_realname}-${pkgver}

  make #VERBOSE=1
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR=${pkgdir} install
}
